package com.dayatang.hrm.compensation.policy;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.dayatang.commons.domain.AbstractEntity;
import com.dayatang.commons.domain.InstanceFactory;

/**
 * 数据计算策略抽象
 * 
 * @author chencao
 * 
 */
@Entity
// @Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@Table(name = "pay_policy_data_cal")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "data_cal_policy_type", discriminatorType = DiscriminatorType.INTEGER)
public abstract class DataCalculatePolicy extends AbstractEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -9113792717310348813L;

	private static DataCalculatePolicyRepository dataCalculatePolicyRepository;

	public DataCalculatePolicy() {
	}

	public static DataCalculatePolicyRepository getDataCalculatePolicyRepository() {
		if (dataCalculatePolicyRepository == null) {
			dataCalculatePolicyRepository = InstanceFactory
					.getInstance(DataCalculatePolicyRepository.class);
		}
		return dataCalculatePolicyRepository;
	}

	public static void setDataCalculatePolicyRepository(
			DataCalculatePolicyRepository dataCalculatePolicyRepository) {
		DataCalculatePolicy.dataCalculatePolicyRepository = dataCalculatePolicyRepository;
	}

	@Column(name = "data_cal_policy_name")
	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof DataCalculatePolicy == false) {
			return false;
		}
		if (this == obj) {
			return true;
		}
		DataCalculatePolicy rhs = (DataCalculatePolicy) obj;
		return new EqualsBuilder().append(getId(), rhs.getId()).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder(17, 37).append(getId()).toHashCode();
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this,
				ToStringStyle.SHORT_PREFIX_STYLE);
	}

}
